package com.fcscs.cservice.client.main.configuration.iguest;


import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.event.StateEvent;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.VerticalPanel;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.Radio;
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.fcscs.core.gwt.common.CoreConstants;
import com.fcscs.core.gwt.common.ui.BaseDialog;
import com.fcscs.core.gwt.common.ui.FcsFields.FormButton;
import com.fcscs.cservice.client.common.CServiceConstants;
import com.fcscs.cservice.client.main.ui.DialogEvent;
import com.fcscs.cservice.client.main.ui.DialogEventHandler;
import com.google.gwt.user.client.Window;

public class iGuestLoginOptionDialog extends BaseDialog{
	private static iGuestLoginOptionDialog INSTANCE;
	private MyFormPanel myFormPanel1;
	
	public enum LoginOption{
		USERNAME_PASS, ACCESS_CODE
	}
	
	
	//var option=new Array();
	public static iGuestLoginOptionDialog getInstance() {

		if (null == INSTANCE) {
			INSTANCE = new iGuestLoginOptionDialog();
		}
		//INSTANCE.bookHisSearch();
		INSTANCE.setHeading(CServiceConstants.CSERVICE_CONSTANTS.loginoption());
		INSTANCE.setButtons("");
		return INSTANCE;
	}

	private iGuestLoginOptionDialog() {
		myFormPanel1 = new MyFormPanel();
		//myFormPanel1.
		setSize(400, 200);
	}

	public class MyFormPanel  {
		

		private FormButton okButton;
		private FormButton cancelButton;
		 MyFormPanel() {
			//setHeaderVisible(false);
			VerticalPanel vp1=new VerticalPanel();
			vp1.setBorders(true);
			vp1.setSpacing(5);
			
			HorizontalPanel hp1=new HorizontalPanel();
			hp1.setId("iGuestLoginOptionDialog_left1");
			hp1.setSpacing(5);
			
			VerticalPanel hv1=new VerticalPanel();
			hv1.setSpacing(5);

			
			
			
			
			
			VerticalPanel hv2=new VerticalPanel();
			hv2.setSpacing(5);
			
			final SimpleComboBox<String> cbusername=new SimpleComboBox<String>();
			//cbusername.setDisplayField("Username");
			cbusername.setEditable(false);
			cbusername.setWidth(100);
			cbusername.add("Room No");
			cbusername.add("Surname");
			cbusername.add("1st Name");
			cbusername.add("Guest ID");
			cbusername.add("Random");
			cbusername.setTriggerAction(TriggerAction.ALL);
			cbusername.setSimpleValue("Room No");
			hv2.add(cbusername);
			
			final TextField<String> randcode = new TextField<String>();
			randcode.setWidth(100);
			randcode.setReadOnly(true);
			randcode.setId("LogonOptionDialog_randomcodeTextField");
			randcode.setValue("Random 4 AN");
			randcode.setVisible(true);
			//randcode.setEnabled(false);
		    hv2.add(randcode);
			
			VerticalPanel hv3=new VerticalPanel();
			hv3.setSpacing(5);
			final SimpleComboBox<String> cbpassword=new SimpleComboBox<String>();
			cbpassword.setEditable(false);
			cbpassword.setWidth(100);
			cbpassword.add("Room No");
			cbpassword.add("Surname");
			cbpassword.add("1st Name");
			cbpassword.add("Guest ID");
			cbpassword.add("Random");
			cbpassword.setTriggerAction(TriggerAction.ALL);
			cbpassword.setSimpleValue("Room No");
			hv3.add(cbpassword);
//			Radio button
			final Radio usernamepass=new Radio();
			usernamepass.setId("iGuestLoginOptionDialog_radio");
			usernamepass.setBoxLabel(CoreConstants.CORE_CONSTANTS.username()+" "+CoreConstants.CORE_CONSTANTS.pwd());
			usernamepass.setValue(true);
			//usernamepass.setValue(Boolean.)(String.valueOf(1));
			usernamepass.addListener(Events.Select, new Listener<BaseEvent>() {

					@Override
					public void handleEvent(BaseEvent be) {
						if (usernamepass.getValue()) {
							cbusername.setEnabled(true);
							cbpassword.setEnabled(true);
						}else {
							cbusername.setEnabled(false);
							cbpassword.setEnabled(false);
						}
					}
				});
			final Radio accesscode=new Radio();
			accesscode.setBoxLabel(CServiceConstants.CSERVICE_CONSTANTS.accesscode());
			accesscode.setValue(false);
			accesscode.addListener(Events.Select, new Listener<BaseEvent>() {

				@Override
				public void handleEvent(BaseEvent be) {
					if (accesscode.getValue()) {
						randcode.setEnabled(true);
					}else {
						randcode.setEnabled(false);
					}
				}
			});
			RadioGroup radioGroup = new RadioGroup();  
		    radioGroup.add(usernamepass);
		    radioGroup.setOrientation(Orientation.VERTICAL);
		    radioGroup.add(accesscode);  
		    //radioGroup.setData("text", "Login Option");  
		    hv1.add(radioGroup);
			hp1.add(hv1);
			hp1.add(hv2);
			hp1.add(hv3);
			vp1.add(hp1);
			
			HorizontalPanel hp2=new HorizontalPanel();
			hp2.setStyleAttribute(CServiceConstants.CSS_MARGINTOP, "50px");
			hp2.setSpacing(5);
			
			okButton = new FormButton(CoreConstants.CORE_CONSTANTS.ok());
			okButton.setId("iGuestLoginOptionDialog_okButton_id");
			okButton.setStyleAttribute(CServiceConstants.CSS_MARGINLEFT, "230px");
			okButton.setWidth(60);
			okButton.addSelectionListener(new SelectionListener<ButtonEvent>(){
				@Override
				
				public void componentSelected(ButtonEvent ce) {
					if(usernamepass.getValue()){
						DialogEvent.fireOkEvent(INSTANCE, new DialogEvent(LoginOption.USERNAME_PASS, cbusername.getSimpleValue(),cbpassword.getSimpleValue()));//DialogEvent(username, password);
						
					}else{
						DialogEvent.fireOkEvent(INSTANCE, new DialogEvent(LoginOption.ACCESS_CODE, null,randcode.getValue()));//DialogEvent(username, password);
						
					}
					iGuestLoginOptionDialog.this.hide();
				}
			});
			
			cancelButton = new FormButton(CoreConstants.CORE_CONSTANTS.cancel());
			cancelButton.setId("iGuestLoginOptionDialog_okButton_id");
			cancelButton.setWidth(60);
			cancelButton.addSelectionListener(new SelectionListener<ButtonEvent>(){
				@Override
				public void componentSelected(ButtonEvent ce) {
					iGuestLoginOptionDialog.this.hide();
				}
			});
			hp2.add(okButton);
			hp2.add(cancelButton);
			vp1.add(hp2);
			
			add(vp1);
		}

		
	}
	@Override
	public void setFocus() {
		// TODO Auto-generated method stub
		
	}

}
